/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import dao.LiveServersDao;
import dao.LiveServersTaskDao;
import java.sql.Connection;
import java.util.Vector;
import pojo.LiveServers;
import pojo.MyLST;

/**
 *
 * @author A7med Kotb
 */
public class LiveServersModel 
{
    private Connection con;

    public LiveServersModel(Connection con) {
        this.con = con;
    }

    //method to add new live server to our servers
    public boolean add(LiveServers ls,MyLST lst)
    {
        boolean check=false;
        LiveServersDao lsd=new LiveServersDao(con);
        check=lsd.insert(ls);
        LiveServers oldls=lsd.getByIp(ls.getIp());
        lst.setLstId(oldls.getLsId());
        LiveServersTaskDao lstd=new LiveServersTaskDao(con);
        check=lstd.insert(lst);
        return check;
    }
    
    public LiveServers getByName(String ip)
    {
        LiveServersDao lsd=new LiveServersDao(con);
        return lsd.getByIp(ip);
    }
    
    public MyLST getById(int id)
    {
        LiveServersTaskDao lstd=new LiveServersTaskDao(con);
        return lstd.getById(id);
    }
    
    //method to update live server data
    public boolean update(LiveServers ls ,MyLST lst)
    {
        boolean check=false;
        LiveServersDao lsd=new LiveServersDao(con);
        LiveServersTaskDao lstd=new LiveServersTaskDao(con);
        check=lsd.update(ls);
        check=lstd.update(lst);
        return check;
    }
    
    public Vector<LiveServers>getAllServers()
    {
       Vector<LiveServers> servers=new Vector<LiveServers>();
       LiveServersDao lsdao=new LiveServersDao(con);
       servers=lsdao.getall();
       return servers;
    }

    //method to delete live server data from database
    public boolean deleteLiveServer(String ip) 
    {
       LiveServersDao ldao=new LiveServersDao(con);
       return ldao.deleteByIp(ip);
    }

    //method to delete live server task data from database
    public boolean deleteLiveServerTask(int lstId) 
    {
        LiveServersTaskDao ltdao=new LiveServersTaskDao(con);
        return ltdao.deleteById(lstId);
    }
}
